package jsp;

import util.CookieUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Miss Chen
 * @version 1.0
 * @date 2024年09月03日15:06
 */

@WebServlet("*.cookie2")
public class CookieTwoServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String path=request.getServletPath();
        if("/add.cookie2".equals(path)){
            addCookie(request,response);
        }
        if("/findAll.cookie2".equals(path)){
            findAll(request,response);
        }
        if("/modify.cookie2".equals(path)){
            modifyCookie(request,response);
        }
        if("/deleteCookie.cookie2".equals(path)){
            deleteCookie(request,response);
        }
    }
    public void addCookie(HttpServletRequest request, HttpServletResponse response){
        CookieUtil.addCookie("username","admin",response);
    }
    public void findAll(HttpServletRequest request, HttpServletResponse response){
        String username=CookieUtil.findByName("username",request);
        String password=CookieUtil.findByName("password",request);
        String name=CookieUtil.findByName("name",request);
        System.out.println("username:"+username+",password:"+password+",name:"+name);
    }
    public void modifyCookie(HttpServletRequest request, HttpServletResponse response){
        CookieUtil.modifyCookie("username","aaaa",response);
    }
    public void deleteCookie(HttpServletRequest request, HttpServletResponse response){
        CookieUtil.deleteCookie("username",response);
    }
}
